home *** CD-ROM | disk | FTP | other *** search
- Path: news.primenet.com!not-for-mail
- From: gbe@primenet.com (Gary Edstrom)
- Newsgroups: comp.lang.c++
- Subject: Bug? MSVC++ 4.0, Windows 95, Virtual Destructors, & DLL's
- Date: 6 Feb 1996 17:28:02 -0700
- Organization: Sequoia Software
- Sender: root@primenet.com
- Message-ID: <3117efd3.956426@news.primenet.com>
- X-Posted-By: ip076.lax.primenet.com
- X-Newsreader: Forte Agent .99c/16.141
-
- Here's a strange problem that I have been trying to figure out all day
- today. I have a program that consists of 2 parts:
-
- 1. A DLL that contains a simple class with an empty constructor
- and an empty virtual destructor.
-
- 2. An EXE that contains exactly the same type of class, but with a
- different name.
-
- All I do in the main program is to create an instance of the object
- via new, followed by an immediate delete object. I do this for both
- types of objects. The object that is defined in the main test module
- functions as expected. However, when the function defined in the DLL
- is deleted, I get an assertion error from the debug library showing
- some sort of corruption on the heap.
-
- IMPORTANT:
- This example will only show the problem if compiled in the Debug mode.
-
- Can anyone else duplicate this problem? Does anyone have any idea
- what is going on? Have I come across some sort of compiler bug? The
- only clue that I seem to have discovered is that the first version
- (the one resident in the EXE file) executes an internal function
- called "scaler deleting destructor", while the second version (the one
- defined in the DLL file) executes an internal function called "vector
- deleting destructor".
-
-
- ********* CONTENTS OF DLL.H **********
-
- #ifdef DLL_OP
- #define Dll_Decl __declspec( dllexport )
- #else
- #define Dll_Decl __declspec( dllimport )
- #endif
-
- class Dll_Decl object1
- {
- public:
- object1();
- virtual ~object1();
- };
-
- ********* CONTENTS OF DLL.C *********
-
- #include "windows.h"
- #define DLL_OP
- #include "ipc.h"
-
- object1::object1() { }
- object1::~object1() { }
-
- ********* CONTENTS OF TEST.CPP *********
-
- #define STRICT
- #include <windows.h>
-
- #include "dll.h"
-
- class object2
- {
- public:
- object2();
- virtual ~object2();
- };
-
- object2::object2() { }
- object2::~object2() { }
-
- int WINAPI WinMain(
- HINSTANCE hInstance, // handle to current instance
- HINSTANCE hPrevInstance, // handle to previous instance
- LPSTR lpCmdLine, // pointer to command line
- int nShowCmd // show state of window
- )
- {
-
- {
- object2 * o2 = new object2;
- delete o2; // This delete executes OK
- }
-
- {
- object1 * o1 = new object1;
- delete o1; // This delete produces an assertion error
- }
-
- return 0;
- }
-
- ********* END OF SAMPLE CODE *********
- --
- Gary Edstrom <gbe@primenet.com> | Sequoia Software
- PO Box 9573 | Programming & Technical Services
- Glendale CA 91226-0573 | PGP Key ID: 0x1A0D44BD
- PGP Fingerprint: 72 AA 4F 73 05 53 89 C6 8A EE F4 EE D1 C0 13 8D
-